<!-- 中英文切换 -->
<template>
  <div class="box">
    <el-dropdown trigger="click">
      <span class="languageText">
        {{languageText === 'en'?$t('lan.en'):$t('lan.zh')}}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="switchLan($t('lan.en'),'en')">{{$t('lan.en')}}</el-dropdown-item>
        <el-dropdown-item @click.native="switchLan($t('lan.zh'),'zh')">{{$t('lan.zh')}}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
<script>
export default {
  data () {
    return {
      languageText: localStorage.getItem('languageSet') || 'en'
    }
  },
  methods: {
    switchLan (val, code) {
      localStorage.setItem('languageSet', code)
      window.location.reload()
    }
  },
  mounted () {
    if (!localStorage.getItem('languageSet')) localStorage.setItem('languageSet', 'en')
  }
}
</script>
<style scoped>
.box {
  display: inline-block;
}
.languageText {
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
</style>